package com.yunbao.controller;

import com.yunbao.pojo.Response;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by louisyuu on 2020/3/14 下午10:25
 */


@Controller
public class UserController {

    private final static String DEFAULT_USERNAME = "admin";

    private final static String DEFAULT_PASSWORD = "admin";


    public final static Set<String> MOCK_LOGIN = new HashSet<>();


    @RequestMapping("/login")
    @ResponseBody
    public Response login(HttpServletRequest request, String username, String password) {
        Response response = new Response();

        if (username == null || password == null) {
            response.setMsg("登录用户名密码不能为空");
            return response;
        }
        if (!DEFAULT_USERNAME.equals(username)) {
            response.setMsg("账户名或密码错误");
            return response;
        }
        if (!DEFAULT_PASSWORD.equals(password)) {
            response.setMsg("账户名或密码错误");
            return response;
        }

        MOCK_LOGIN.add(DEFAULT_USERNAME);
        return response;

    }


    public static boolean isLogin() {
        return MOCK_LOGIN.contains(DEFAULT_USERNAME);
    }


    public String login(){
       return "redirect:/html/login.html";
    }

}
